package com.xipu.write;

import com.alibaba.excel.EasyExcel;
import com.xipu.entity.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * description: WriteExcel 写操作
 * @author: gql
 * @date: 2021/11
 */
public class WriteExcel {
    public static void main(String[] args) {
        // 向list集合添加100条数据
        List<Student> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Student stud = new Student();
            stud.setId(i);
            stud.setUsername("郭乾亮" + i + "号");
            stud.setGender("男");
            stud.setSalary(100000.00);
            list.add(stud);
        }

        // 设置excel文件路径和文件名称
        String fileName = "D:\\01.xlsx";

        // write方法实现写操作
        EasyExcel.write(fileName, Student.class)
                .sheet("用户信息")
                .doWrite(list);
    }
}
